# -*- coding: utf-8 -*-
#作者：廖雄雄
#保存路径：C:\Users\Administrator\PycharmProjects
from PyQt5.QtWidgets import *
import sys
from PyQt5 import QtCore
import pandas as pd  # 数据处理
import matplotlib.pyplot as plt
import scipy.stats as stats
plt.rcParams['font.sans-serif']=['SimHei']
class MainWindow(QMainWindow):
   def __init__(self, parent=None):
       super(MainWindow, self).__init__(parent)
       self.setWindowTitle('数据处理v1.0')
       self.resize(1000,800)
       self.move(500,100)
       #创建菜单
       self.bar = QMenuBar(self)
       self.layout = QVBoxLayout(self)
       #导入数据
       self.file = self.bar.addMenu("数据")
       self.data = QAction("导入文件")
       self.save = QAction("保存", self)
       self.file.addAction(self.data)
       self.file.addAction(self.save)
       self.data.triggered.connect(self.taskdata)
       self.save.triggered.connect(self.tasksave)
       #集中趋势分析
       self.dataanalyse = self.bar.addMenu("集中趋势分析")
       self.mean = QAction("均值",self)
       self.median = QAction("中位数", self)
       self.mode = QAction("众数", self)
       self.dataanalyse.addAction(self.mean)
       self.dataanalyse.addAction(self.median)
       self.dataanalyse.addAction(self.mode)
       self.mean.triggered.connect(self.taskmean)
       self.median.triggered.connect(self.taskmedian)
       self.mode.triggered.connect(self.taskmode)
       #创建离散趋势
       self.dataanalyse_discrete = self.bar.addMenu("离散趋势分析")
       self.range= QAction("极差",self)
       self.quantile = QAction("四分位差", self)
       self.var = QAction("方差", self)
       self.std = QAction("标准差", self)
       self.dataanalyse_discrete.addAction(self.range)
       self.dataanalyse_discrete.addAction(self.quantile)
       self.dataanalyse_discrete.addAction(self.var)
       self.dataanalyse_discrete.addAction(self.std)
       self.range.triggered.connect(self.taskrange)
       self.quantile.triggered.connect(self.taskquantile)
       self.var.triggered.connect(self.taskvar)
       self.std.triggered.connect(self.taskstd)
       self.plot = self.bar.addMenu("画图")
       self.plot_zhexiantu=QAction('折线图')
       self.plot_zhuxingtu = QAction('柱形图')
       self.plot_bingtu = QAction('饼图')
       self.plot_sandiantu=QAction("散点图")
       self.ttest=self.bar.addMenu("假设检验")
       self.ttest_single=QAction("单样本T检验")
       self.anova=self.bar.addMenu("方差分析")
       self.anova_single=QAction("单因素方差分析")
       self.anova.addAction(self.anova_single)
       self.plot.addAction(self.plot_zhexiantu)
       self.plot.addAction(self.plot_zhuxingtu)
       self.plot.addAction(self.plot_bingtu)
       self.plot.addAction(self.plot_sandiantu)
       self.ttest.addAction(self.ttest_single)
       self.plot_zhexiantu.triggered.connect(self.taskplot_zhexiantu)
       self.plot_zhuxingtu.triggered.connect(self.taskplot_zhuxingtu)
       self.plot_bingtu.triggered.connect(self.taskplot_bingtu)
       self.plot_sandiantu.triggered.connect(self.taskplot_sandiantu)
       self.anova_single.triggered.connect(self.taskAnova_single)
       self.ttest_single.triggered.connect(self.taskSingle)
       self.setMenuBar(self.bar)
       #创建文本框
       self.text = QTextEdit(self)
       self.text.resize(600,800)
       self.text.setGeometry(QtCore.QRect(10,150, 978, 600))
       self.layout.addWidget(self.text)

       self.setLayout(self.layout)
       #读取数据
   def taskdata(self):
        global raw_data
      # 设置全局变量，用于其他功能实现
        input_file, ftype = QFileDialog.getOpenFileName(self, "打开文件", '.', "(*.*)")#打开文件
        raw_data = pd.read_csv(input_file, encoding='gbk')  # 读取文件
        raw_data = raw_data.dropna()  # 缺失值处理,丢弃所有缺失值所在的
        pd.set_option('display.max_columns', None)  # 显示全部行
        pd.set_option('display.max_row', None)  # 显示全部列
        text=str(raw_data)
        self.text.setPlainText(text)#将数据插入文本框
        #print(raw_data.columns[1])
        #a = len(raw_data.columns)获取数据的列长
        #均值
   def taskmean(self):
      mean=datadialogmean()
      mean.exec_()
    #中位数
   def taskmedian(self):
       median=datadialogmedian()
       median.exec_()
       #众数
   def taskmode(self):
       mode = datadialogmode()
       mode.exec_()
   #保存
   def tasksave(self):
       pass
   #极差
   def taskrange(self):
       range = datadialogrange()
       range.exec_()
   #四分位差
   def taskquantile(self):
       quantile = datadialogquantile()
       quantile.exec_()
   #方差
   def taskvar(self):
        var = datadialogvar()
        var.exec_()
    #标准差
   def taskstd(self):
        std = datadialogstd()
        std.exec_()
   def taskplot_zhexiantu(self):
       zhexiantu=datadialogzhexiantu()
       zhexiantu.exec_()
   def taskplot_zhuxingtu(self):
       zhuxingtu=datadialogzhuxingtu()
       zhuxingtu.exec_()
   def taskplot_bingtu(self):
       zhuxingtu=datadialogbingtu()
       zhuxingtu.exec_()
   def taskplot_sandiantu(self):
       sandiantu = datadialogsandiantu()
       sandiantu.exec_()
   def taskSingle(self):
       single=DataDialogSingleTTest()
       single.exec_()
   def taskAnova_single(self):
       anovaSingle=DataDialogAnovaSingle()
       anovaSingle.exec_()
class datadialogmean(QDialog):
    #子窗口
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('均值')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        #print(raw_data.columns[1])
        #print(len(raw_data.columns))
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)###
        #item1
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
        #item2
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
        #处理均值
    def clicked0(self):
        count=self.list2.count()
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].mean().round(2)
           list.append(text)
        text=str(list)
        self.text.setText(text)
class datadialogmedian(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('中位数')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        #print(count)
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].median().round(2)
           list.append(text)
        text=str(list)
        self.text.setText(text)
class datadialogmode(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('众数')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        #print(raw_data.columns[1])
        #print(len(raw_data.columns))
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        #print(count)
        list=[]
        for i in range(count):
           #print(self.list2.item(i).text())
           #name=self.list2.item(i).text()
           #print(raw_data[name])
           text=raw_data[self.list2.item(i).text()].mode()
           list.append(text)
        text=str(list)
        #for i in range(len(list)):
         #   text=str(list[i])
        self.text.setText(text)
class datadialogrange(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('极差')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        #print(raw_data.columns[1])
        #print(len(raw_data.columns))
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        #print(count)
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].max().round(2)-raw_data[self.list2.item(i).text()].min().round(2)
           list.append(text)
        list2=[]
        for i in range(len(list)):
            range_=str(list[i])
            list2.append(range_)
        text=str(list)
        #for i in range(len(list)):
         #   text=str(list[i])
        self.text.setText(text)
class datadialogquantile(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('四分位数')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].quantile([0.25,0.5,0.75]).round(2)
           list.append(text)
        text=str(list)
        self.text.setText(text)
class datadialogvar(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('方差')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].var().round(2)
           list.append(text)
        text=str(list)
        self.text.setText(text)
class datadialogstd(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('标准差')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        list=[]
        for i in range(count):
           text=raw_data[self.list2.item(i).text()].std().round(2)
           list.append(text)
        text=str(list)
        self.text.setText(text)
class datadialogzhexiantu(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('折线图')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count=self.list2.count()
        list=[]
        for i in range(count):
            list.append(self.list2.item(i).text())
        plt.title('折线图', loc='center')
        if (count==2):
            plt.xlabel(list[0])
            plt.ylabel(list[1])
        else:
            plt.xlabel(list[0])
            print(list[1:])
        for i in range(1, count):
            plt.plot(raw_data[list[0]], raw_data[list[i]],label=list[i])#第一列为x轴，第其余列为y轴
        plt.legend(loc=1)
        plt.show()
class datadialogzhuxingtu(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('柱形图')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count = self.list2.count()
        list = []
        for i in range(count):
            list.append(self.list2.item(i).text())
        plt.title('柱形图', loc='center')
        plt.legend(list)
        for i in range(1, count):
            plt.bar(raw_data[list[0]], raw_data[list[i]])
        plt.show()
class datadialogbingtu(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('饼图')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count = self.list2.count()
        list = []
        for i in range(count):
            list.append(self.list2.item(i).text())
        data=raw_data[list[0]].value_counts()
        data.name = ''
        plt.axes(aspect='equal')# 控制饼图为正圆
        # plot方法对序列进行绘图
        data.plot(kind='pie',  # 选择图形类型
                   autopct='%.1f%%',  # 饼图中添加数值标签
                   radius=1,  # 设置饼图的半径
                   startangle=180,  # 设置饼图的初始角度
                   counterclock=False,  # 将饼图的顺序设置为顺时针方向
                   title='饼图',  # 为饼图添加标题
                   wedgeprops={'linewidth': 1.5, 'edgecolor': 'green'},  # 设置饼图内外边界的属性值
                   textprops={'fontsize': 10, 'color': 'black'}  # 设置文本标签的属性值
                   )
        # 显示图形
        plt.show()

        #plt.show()
class datadialogsandiantu(QDialog):
    def __init__(self):
        super().__init__()
        self.layout=QHBoxLayout(self)
        self.list1=QListWidget()
        self.setWindowTitle('散点图')
        for i in range(len(raw_data.columns)):
            itemname=raw_data.columns[i]
            self.list1.addItem(itemname)
        self.pb1=QPushButton('统计')
        self.list2=QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.text = QTextEdit(self)
        self.text.resize(600, 800)
        self.text.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.text)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count = self.list2.count()
        list = []
        for i in range(count):
            list.append(self.list2.item(i).text())
        plt.title('散点图', loc='center')
        plt.legend(list)
        for i in range(1, count):
            plt.scatter(raw_data[list[0]], raw_data[list[i]])
        plt.show()
class DataDialogSingleTTest(QDialog):
    def __init__(self):
        super().__init__()
        self.layout = QHBoxLayout(self)
        self.list1 = QListWidget()
        self.setWindowTitle('单样本T检验')
        for i in range(len(raw_data.columns)):
            itemname = raw_data.columns[i]
            self.list1.addItem(itemname)
        self.label_1=QLabel("输入均值")
        self.label_2 = QLabel("输入alpha值")
        self.pb1 = QPushButton('T检验')
        self.list2 = QListWidget()
        self.pb1.setCheckable(True)
        self.pb1.toggle()
        self.pb1.clicked.connect(self.clicked0)
        self.list1.itemClicked.connect(self.clicked1)
        self.list2.itemClicked.connect(self.clicked2)
        self.result = QTextEdit(self)
        self.result.resize(600, 800)
        self.result.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.test_mean_1 = QLineEdit(self)
        self.test_mean_2 = QLineEdit(self)
        self.test_mean_1.resize(600, 800)
        self.test_mean_1.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.test_mean_2.resize(600, 800)
        self.test_mean_2.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.label_1)
        self.layout.addWidget(self.test_mean_1)
        self.layout.addWidget(self.label_2)
        self.layout.addWidget(self.test_mean_2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.result)
        self.setLayout(self.layout)
    def clicked1(self,Index):
        self.list2.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
    def clicked2(self,Index):
        self.list1.addItem(self.list2.item(self.list2.row(Index)).text())
        self.list2.takeItem(self.list2.row(Index))
    def clicked0(self):
        count = self.list2.count()
        list = []
        for i in range(count):
            list.append(self.list2.item(i).text())
        #print(self.test_mean_1.text())
        test_value=pd.to_numeric(self.test_mean_1.text())
        alpha=pd.to_numeric(self.test_mean_2.text())
        stal,p_value=stats.ttest_1samp(raw_data[list[0]],test_value)
        print(p_value,alpha)
        print(type(p_value),type(alpha))
        print(str(alpha))
        if(p_value>alpha):
            #print(str(alpha))
            text="结果：对于给定显著性水平alpha="+str(alpha)+"其检测概率p_value>"+str(alpha)+"所以不能拒绝原假设，认为"+list[0]+"列的均值为"+str(test_value)+"。"
            text1=str(text)
            self.result.setText(text1)

        else:
            text = "结果：对于给定显著性水平alpha="+str(alpha)+"其检测概率p_value<"+str(alpha)+"所以拒绝原假设，认为"+list[0]+"列的均值不为"+str(test_value)+"。"
            text1 = str(text)
            self.result.setText(text1)
class DataDialogAnovaSingle(QDialog):
    def __init__(self):
        super().__init__()
        self.layout = QHBoxLayout(self)
        self.list1 = QListWidget()
        self.setWindowTitle('单因素方差分析')
        for i in range(len(raw_data.columns)):
            itemname = raw_data.columns[i]
            self.list1.addItem(itemname)

        self.le1=QLineEdit()

        self.pb0=QPushButton('x')
        self.pb1 = QPushButton('y')
        self.pb2 = QPushButton('统计')
        self.list2 = QListWidget()
        self.list3=QListWidget()
        self.list1.itemClicked.connect(self.clicked3)
        self.pb0.clicked.connect(self.clicked0)
        self.pb1.clicked.connect(self.clicked1)
        self.pb2.clicked.connect(self.clicked2)
        self.result = QTextEdit(self)
        self.result.resize(600, 800)
        self.result.setGeometry(QtCore.QRect(10, 150, 978, 600))
        self.layout.addWidget(self.list1)
        self.layout.addWidget(self.pb0)
        self.layout.addWidget(self.list2)
        self.layout.addWidget(self.pb1)
        self.layout.addWidget(self.list3)
        self.layout.addWidget(self.pb2)
        self.layout.addWidget(self.result)
        self.layout.addWidget(self.le1)
        self.setLayout(self.layout)
    def clicked3(self,Index):
        print(Index)
        self.le1.setText(self.list1.item(self.list1.row(Index)).text())
    def clicked0(self):

        #print(Index)
        print(self.le1.text())

        self.list2.addItem(self.le1.text())
        self.list1.itakeItem(self.le1.text())
    def clicked1(self,Index):
        pass
        '''
        self.list3.addItem(self.list1.item(self.list1.row(Index)).text())
        self.list1.takeItem(self.list1.row(Index))
        '''
    def clicked2(self):
        '''
        count = self.list2.count()
        list = []
        for i in range(count):
            list.append(self.list2.item(i).text())
        #print(self.test_mean_1.text())
        test_value=pd.to_numeric(self.test_mean_1.text())
        alpha=pd.to_numeric(self.test_mean_2.text())
        stal,p_value=stats.ttest_1samp(raw_data[list[0]],test_value)
        print(p_value,alpha)
        print(type(p_value),type(alpha))
        print(str(alpha))
        if(p_value>alpha):
            #print(str(alpha))
            text="结果：对于给定显著性水平alpha="+str(alpha)+"其检测概率p_value>"+str(alpha)+"所以不能拒绝原假设，认为"+list[0]+"列的均值为"+str(test_value)+"。"
            text1=str(text)
            self.result.setText(text1)

        else:
            text = "结果：对于给定显著性水平alpha="+str(alpha)+"其检测概率p_value<"+str(alpha)+"所以拒绝原假设，认为"+list[0]+"列的均值不为"+str(test_value)+"。"
            text1 = str(text)
            self.result.setText(text1)
        '''
if __name__ == '__main__':
   app=QApplication(sys.argv)
   mainWindow = MainWindow()
   mainWindow.show()
   sys.exit(app.exec_())
